package com.zeny.mycrm.service.impl;

import com.zeny.mycrm.dao.CourseOrderDao;
import com.zeny.mycrm.model.CourseOrder;
import com.zeny.mycrm.model.PageResult;
import com.zeny.mycrm.service.CourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName CourseOrderServiceImpl
 * @Description TODO
 * @Author zeny
 */
@Service
public class CourseOrderServiceImpl implements CourseOrderService {

    @Autowired
    private CourseOrderDao courseOrderDao;


    @Override
    public PageResult findListByMap(CourseOrder condition, int page, int size) {
        PageResult result = new PageResult();
        Map<String, Object> params = new HashMap<>();
        if (condition == null) {
            condition = new CourseOrder();
        }
        params.put("condition", condition);
        Integer totalCount = courseOrderDao.findCountByMap(params);
        result.count(totalCount);

        params.put("page", (page - 1) * size);
        params.put("size", size);
        List<CourseOrder> courseOrderList = courseOrderDao.findListByMap(params);
        result.data(courseOrderList);
        return result;
    }

    @Transactional
    @Override
    public void save(CourseOrder courseOrder) {
        courseOrderDao.insert(courseOrder);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return courseOrderDao.findByOrderId(order_id);
    }

    @Override
    public void delByOrderId(String order_id) {
        courseOrderDao.delByOrderId(order_id);
    }

    @Override
    public void update(CourseOrder courseOrder) {
        courseOrderDao.update(courseOrder);
    }
}
